package com.zego.wawaji.ui.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONObject;

/**
 * 登录解析类
 */
public class LoginResult extends BaseData implements Parcelable {
    private long uid;
    private String auth;   // cookie
    private boolean isNew; // 是否是新用户

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonRes = getJsonObject(jsonStr);

        this.uid = jsonRes.optLong("Id");
        this.auth = jsonRes.optString("Auth");
        this.isNew = jsonRes.optBoolean("IsNew");
    }

    public String getAuth() {
        return auth;
    }

    public long getUid() {
        return uid;
    }

    public boolean isNew() {
        return isNew;
    }

    public LoginResult() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.uid);
        dest.writeString(this.auth);
        dest.writeByte(this.isNew ? (byte) 1 : (byte) 0);
    }

    protected LoginResult(Parcel in) {
        this.uid = in.readLong();
        this.auth = in.readString();
        this.isNew = in.readByte() != 0;
    }

    public static final Creator<LoginResult> CREATOR = new Creator<LoginResult>() {
        @Override
        public LoginResult createFromParcel(Parcel source) {
            return new LoginResult(source);
        }

        @Override
        public LoginResult[] newArray(int size) {
            return new LoginResult[size];
        }
    };
}
